﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SLControlLibrary.Resources.Common
{
    public class Utility
    {
        #region ConvertStringToColor
        public static SolidColorBrush ConvertStringToColor(string _Name)
        {
            if (_Name.Length > 0)
            {
                string _Color = "<SolidColorBrush xmlns='http://schemas.microsoft.com/client/2007'";
                _Color += " xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'";
                _Color += " Color='" + _Name + "'/>";
                return (SolidColorBrush)System.Windows.Markup.XamlReader.Load(_Color);
            }
            else
                return new SolidColorBrush();
        }
        #endregion

        #region FormatDate
        public static string FormatDate(Enumerations.DateFormat FormatValue, DateTime Value)
        {
            string returnDate = Value.ToShortDateString();

            switch (FormatValue)
            {
                case Enumerations.DateFormat.LongMonthDayLongStringYear:
                    returnDate = Value.ToString("MMMM dddd, yyyy");
                    break;
                case Enumerations.DateFormat.LongMonthDayNumberYear:
                    returnDate = Value.ToString("MMMM dd, yyyy");
                    break;
                case Enumerations.DateFormat.LongMonthYear:
                    returnDate = Value.ToString("MMMM yyyy");
                    break;
                case Enumerations.DateFormat.ShortMonthDayNumberYear:
                    returnDate = Value.ToString("MMM dd, yyyy");
                    break;
                case Enumerations.DateFormat.ShortMonthDayShortStringYear:
                    returnDate = Value.ToString("MMM ddd, yyyy");
                    break;
                case Enumerations.DateFormat.LongDay:
                    returnDate = Value.ToString("dddd");
                    break;
                case Enumerations.DateFormat.ShortMonth:
                    returnDate = Value.ToString("MMM");
                    break;
                case Enumerations.DateFormat.LongMonth:
                    returnDate = Value.ToString("MMMM");
                    break;
            }

            return returnDate;
        }
        #endregion

        #region RoundTime
        public static TimeSpan RoundTime(TimeSpan ts, Enumerations.TimeSlotsPerHour TimeSlot)
        {
            TimeSpan retVal = ts;

            switch (TimeSlot)
            {
                case Enumerations.TimeSlotsPerHour.Five:
                    break;
                case Enumerations.TimeSlotsPerHour.Six:
                    break;
                case Enumerations.TimeSlotsPerHour.Ten:
                    break;
                case Enumerations.TimeSlotsPerHour.Fifteen:
                    if (ts.Minutes > 0 && ts.Minutes <= 8)
                        retVal = retVal.Subtract(new TimeSpan(0, ts.Minutes, 0));
                    else if (ts.Minutes > 8 && ts.Minutes <= 15)
                        retVal = retVal.Add(new TimeSpan(0, 15 - ts.Minutes, 0));
                    else if (ts.Minutes > 15 && ts.Minutes <= 23)
                        retVal = retVal.Subtract(new TimeSpan(0, ts.Minutes - 15, 0));
                    else if (ts.Minutes > 23 && ts.Minutes <= 30)
                        retVal = retVal.Add(new TimeSpan(0, 30 - ts.Minutes, 0));
                    else if (ts.Minutes > 30 && ts.Minutes < 38)
                        retVal = retVal.Subtract(new TimeSpan(0, ts.Minutes - 30, 0));
                    else if (ts.Minutes > 38 && ts.Minutes <= 45)
                        retVal = retVal.Add(new TimeSpan(0, 45 - ts.Minutes, 0));
                    else if (ts.Minutes > 45 && ts.Minutes <= 53)
                        retVal = retVal.Subtract(new TimeSpan(0, ts.Minutes - 45, 0));
                    else if (ts.Minutes > 53 && ts.Minutes <= 60)
                    {
                        retVal = retVal.Add(new TimeSpan(1, 0, 0));
                        retVal = retVal.Subtract(new TimeSpan(0, ts.Minutes, 0));
                    }
                    break;
                case Enumerations.TimeSlotsPerHour.Thirty:
                    break;
            }

            return retVal;
        }
        #endregion
    }
}
